package com.lhoverc.mapper;

import com.lhoverc.pojo.VO.ActivityVO;
import com.lhoverc.pojo.VO.RecentActivityVO;
import com.lhoverc.pojo.entity.ActivityEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: LiCheng
 * @CreateTime: 2025-04-20
 * @Description:
 * @Version: 1.0
 */
@Mapper
public interface ActivityMapper {

    /**
     * 按照活动开始时间逆排序，排除被删除的活动
     * @return
     */
    @Select("select * from activity where is_delete = 0 order by activity_start desc")
    List<RecentActivityVO> pageRecentActivity();

    /**
     * 按条件获取活动列表
     * @param activityName
     * @param status
     * @param registrationDate
     * @param activityDate
     * @return
     */
    List<ActivityVO> getActivityList(String activityName, Integer status, LocalDateTime registrationDate, LocalDateTime activityDate);

    /**
     * 添加一个活动
     * @param activityEntity
     */
    @Insert("insert into activity (creator_id, activity_name, description, location, activity_start, activity_deadline, registration_start, registration_deadline, max_participants, image_url, update_time, create_time)" +
            " VALUES (#{creatorId}, #{activityName}, #{description}, #{location}, #{activityStart}, #{activityDeadline}, #{registrationStart}, #{registrationDeadline}, #{maxParticipants}, #{imageUrl}, #{updateTime}, #{createTime})")
    void addActivity(ActivityEntity activityEntity);

    /**
     * 根据id获取活动名
     * @param activityId
     * @return
     */
    @Select("select activity_name from activity where id = #{activityId}")
    String getActivityNameById(Integer activityId);

    /**
     * 删除活动
     * @param id
     */
    @Update("update activity set is_delete = 1 where id = #{id}")
    void deleteActivity(String id);

    /**
     * 修改活动
     * @param activityEntity
     */
    @Update("update activity set activity_name = #{activityName}, description = #{description}, location = #{location}," +
            "image_url = #{imageUrl}, registration_start = #{registrationStart}, registration_deadline = #{registrationDeadline}," +
            "activity_start = #{activityStart}, activity_deadline = #{activityDeadline}, max_participants = #{maxParticipants}," +
            "status = #{status}, update_time = #{updateTime} where id = #{id}")
    void updateActivity(ActivityEntity activityEntity);
}
